package com.blq.developtools.view.viewholder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;

/**
 * <pre>
 * ****************************************************************
 * 文件名称:TemplateViewHolder.java
 * 作 者:SSNB
 * 创建时间:2024/5/21
 * 文件描述:
 * 注意事项:
 * 版权声明:Copyright (C) 2015-2025 杭州中焯信息技术股份有限公司
 * 修改历史:2024/5/21 1.00 初始版本
 * ****************************************************************
 * </pre>
 */
public abstract class TemplateViewHolder<T> {

    private View rootView;
    private T bindData;
    private Context context;

    public TemplateViewHolder(Context context, int layoutID) {
        this(LayoutInflater.from(context).inflate(layoutID, null, false));
    }

    public TemplateViewHolder(View rootView) {
        this.rootView = rootView;
        this.context = rootView.getContext();
        initView(rootView);
        bindEvent();
    }

    protected abstract void initView(View rootView);

    protected abstract void bindEvent();

    public void bindData(T data) {
        this.bindData = data;
        if (isShowView(data)) {
            rootView.setVisibility(View.VISIBLE);
            onBindData(data);
        } else {
            rootView.setVisibility(View.GONE);
        }
    }

    protected abstract void onBindData(T data);

    protected boolean isShowView(T data) {
        return true;
    }

    public View getRootView() {
        return rootView;
    }

    public T getBindData() {
        return bindData;
    }

    public Context getContext() {
        return context;
    }
}
